/*
* @Author: Rosen
* @Date:   2017-05-18 19:30:12
* @Last Modified by:   Rosen
* @Last Modified time: 2017-05-27 19:46:42
*/

'use strict';
require('./index.css');
var _mm     = require('util/mm.js');
// 通用页面头部
var headerName = {
    init : function(){
        this.onLoad();
        this.bindEvent();
    },
    onLoad : function(){
        var condition = _mm.getUrlParam('condition');
        // keyword存在，则回填输入框
        if(condition){
            $('#search-input').val(condition);
        };
    },
    bindEvent : function(){
        var _this = this;
        // 点击搜索按钮以后，做搜索提交
        $('#search-btn').click(function(){
            _this.searchSubmit();
        });
        // 输入会车后，做搜索提交
        $('#search-btn').keyup(function(e){
            // 13是回车键的keyCode
            if(e.keyCode === 13){
                _this.searchSubmit();
            }
        });
    },
    // 搜索的提交
    searchSubmit : function(){
        var name = $.trim($('#search-input').val());
        // name,正常跳转到listHotelName页
        if(name){
            window.location.href = './listMultipleConditions.html?condition=' + name;
        }
        // 如果keyword为空，直接返回首页
        else{
            window.location.href = './listMultipleConditions.html';
        }
    }
};

headerName.init();